package com.ant.map.myuiimmersive.activities;

import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.view.Gravity;
import android.view.TextureView;
import android.widget.LinearLayout;

import com.ant.map.myuiimmersive.R;
import com.ant.utls.base.BaseActivity;

/**
 * Created by baichuan on 2016/12/9.
 */

public class Test003 extends BaseActivity implements TextureView.SurfaceTextureListener {
    private TextureView view;
    private Camera camera;


    @Override
    public int getLaout() {
        return R.layout.ac_test003;
    }

    @Override
    public void initView() {
       view= (TextureView) findViewById(R.id.ac_test003_textureview001);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {

    }

    /**************************************************************************/
    /**
     * textureView start method
     *
     * @param surfaceTexture
     * @param i
     * @param i1
     */
    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {
        camera = Camera.open();
        Camera.Size size = camera.getParameters().getPreviewSize();
        view.setLayoutParams(new LinearLayout.LayoutParams(size.width, size.height, Gravity.CENTER));
        try {
            camera.setPreviewTexture(surfaceTexture);
            camera.startPreview();
//            view.setAlpha(1.0f);
            view.setRotation(90.0f);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i1) {

    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
        camera.stopPreview();
        camera.release();
        return true;
    }

    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {

    }
    /**************************************************************************/
}
